<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template {

	var $CI;
	var $template_data = array(
			'tmp_css'	=> '',
			'tmp_js'	=> ''
		);
	var $resource_path = '';

	function __construct(){
		$this->CI = & get_instance();	
	}

	function set($name,$value)
	{
		$this->template_data[$name] = $value;
	}

	function set_view($name ='', $view ='',$data = array()){
		$this->set($name,$this->CI->load->view($view,$data,TRUE));
	}

	function load($template = '',$data = array(),$view_data = array(), $return = FALSE)
	{  
		foreach ($data as $key => $value)
			if($value != '') $this->set_view($key,$value,$view_data);
			else $this->set($key,'');	
		return $this->CI->load->view($template, $this->template_data, $return);
	}

	private function _set_js($file_name = '',$resource_path = 'RESOURCE/static/')
	{
		if(file_exists($resource_path.$file_name))	
			$this->template_data['tmp_js'].= '<script type="text/javascript" src="'.$resource_path.$file_name.'"></script>';
	}

	private function _set_css($file_name = '',$resource_path = 'RESOURCE/static/')
	{
		
		if(file_exists($resource_path.$file_name))	{

			$this->template_data['tmp_css'].= '<link rel="stylesheet" href="'.$resource_path.$file_name.'"/>';
		}
			
	}	

	function add_css_admin($array = array(),$resource_path = 'RESOURCE/static/')
	{

		if($array)	{
			foreach ($array as $key => $value)	
			{
				$this->_set_css($value,$resource_path);		
			}
		}	
	}

	function add_raw_html($raw_html = '',$position='tmp_js')
	{
		if($raw_html != '')	$this->template_data[$position] .= $raw_html;
	}

	function add_js_admin($array = array(),$resource_path = 'RESOURCE/static/')
	{
		if($array)	
			foreach ($array as $key => $value)	
				$this->_set_js($value,$resource_path);
	}
}

/* End of file Template.php */
/* Location: ./system/application/libraries/Template.php */